home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / Rect.java < prev    next >
Text File  |  1998-10-01  |  4KB  |  134 lines

  1. package symantec.itools.awt.shape;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Color;
  5.  
  6. //  07/30/97    LAB    Updated version to 1.1.  Added contains method.  Modified paint to use the
  7. //                calculated bevel colors if it was in BEVEL_RAISED or BEVEL_LOWERED mode.
  8. //    08/15/97    LAB    Made paint call super.paint to ensure the colors would get updated if needed.
  9.  
  10. /**
  11.  * This class forms the Rectangle shape component.
  12.  * @see symantec.itools.awt.shape.HorizontalLine
  13.  * @see symantec.itools.awt.shape.Square
  14.  * @see symantec.itools.awt.shape.VerticalLine
  15.  * @version 1.1, July 30, 1997
  16.  * @author Symantec
  17.  */
  18. public class Rect extends Shape
  19. {
  20.     /**
  21.      * Constructs a default Rectangle.
  22.      */
  23.     public Rect()
  24.     {
  25.     }
  26.  
  27.     /**  
  28.      * Checks whether this component "contains" the specified (x, y)
  29.      * location, where x and y are defined to be relative to the 
  30.      * coordinate system of this component.  
  31.      * @param x the x coordinate 
  32.      * @param y the y coordinate
  33.      * @see java.awt.Component#getComponentAt
  34.      */
  35.     public boolean contains(int x, int y)
  36.     {
  37.         if (fill)
  38.         {
  39.             return super.contains(x, y);
  40.         }
  41.         else
  42.         {
  43.             if ((y == 0) || (y == height - 1))
  44.                 return ((x >= 0) && (x < width));
  45.             
  46.             if ((x == 0) || (x == width - 1))
  47.                 return ((y >= 0) && (y < height));
  48.                 
  49.             return false;
  50.         }
  51.     }
  52.  
  53.     /**
  54.      * Paints the rectangle using the given graphics context.
  55.      * This is a standard Java AWT method which typically gets called
  56.      * by the AWT to handle painting this component. It paints this component
  57.      * using the given graphics context. The graphics context clipping region
  58.      * is set to the bounding rectangle of this component and its <0,0>
  59.      * coordinate is this component's top-left corner.
  60.      *
  61.      * @param g the graphics context used for painting
  62.      * @see java.awt.Component#repaint
  63.      * @see java.awt.Component#update
  64.      */
  65.     public void paint(Graphics g)
  66.     {
  67.         super.paint(g);
  68.         
  69.         g.clipRect(0, 0, width, height);
  70.  
  71.         int w = width - 1, h = height - 1;
  72.  
  73.         switch (style)
  74.         {
  75.  
  76.             case BEVEL_LINE :
  77.                 if (fill)
  78.                 {
  79.                     g.setColor(fillColor);
  80.                     g.fillRect(0, 0, w, h);
  81.                 }
  82.                 g.setColor(getForeground());
  83.                 g.drawRect(0, 0, w, h);
  84.                 break;
  85.  
  86.             case BEVEL_LOWERED :
  87.                 if (fill)
  88.                 {
  89.                     g.setColor(fillColor);
  90.                     g.fillRect(1, 1, w - 1, h - 1);
  91.                 }
  92.  
  93.                 g.setColor(bevelDarkerColor);
  94.                 g.drawLine(0, h, 0, 0);
  95.                 g.drawLine(0, 0, w, 0);
  96.  
  97.                 g.setColor(bevelLighterColor);
  98.                 g.drawLine(w, 0, w, h);
  99.                 g.drawLine(w, h, 0, h);
  100.  
  101.                 break;
  102.  
  103.             case BEVEL_RAISED :
  104.                 if (fill)
  105.                 {
  106.                     g.setColor(fillColor);
  107.                     g.fillRect(1, 1, w - 1, h - 1);
  108.                 }
  109.                 
  110.                    g.setColor(bevelLighterColor);
  111.                 g.drawLine(0, h, 0, 0);
  112.                 g.drawLine(0, 0, w, 0);
  113.  
  114.                 g.setColor(bevelDarkerColor);
  115.                 g.drawLine(w, 0, w, h);
  116.                 g.drawLine(w, h, 0, h);
  117.  
  118.                 break;
  119.                 
  120.             default :
  121.                 if (fill)
  122.                 {
  123.                     g.setColor(fillColor);
  124.                     g.fillRect(0, 0, width, height);
  125.                 }
  126.                 else
  127.                 {
  128.                     g.setColor(getForeground());
  129.                     g.drawRect(0, 0, w, h);
  130.                 }
  131.         }
  132.     }
  133. }
  134.